package org.gvp.record.controller;

import lombok.RequiredArgsConstructor;

import org.gvp.common.constant.SummerController;
import org.gvp.record.dto.ReportUpdate;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import org.gvp.common.constant.BaseController;
import org.gvp.common.annotation.Operation;
import org.gvp.common.http.Page;
import org.gvp.common.http.Result;
import org.gvp.record.service.ReportService;
import org.gvp.record.pojo.Report;
import java.util.List;

@RestController
@RequestMapping("/record/report")
@RequiredArgsConstructor
public class ReportController implements SummerController<Report> {
    private final ReportService reportService;
    @Operation(value = "添加报销单,并返回新的报销单", param = "报销单对象")
    @PutMapping
    @Override
    public Report addReturn(@RequestBody Report dto) {
        return this.reportService.saveAndReturn(dto);
    }

    @GetMapping("/list")
    @Operation("查找全部报销单")
    @Override
    public List<Report> queryList() {
        return this.reportService.findList();
    }

    @Operation(value = "查找报销单分页数据",param = "page:当前页,size:页大小")
    @GetMapping("/page/{page:\\d+}/{size:\\d+}")
    @Override
    public Page<Report> queryPage(@PathVariable int page,@PathVariable int size) {
        return this.reportService.findPage(page, size);
    }

    @Operation(value = "根据报销单记录", param = "报销单实体类对象")
    @PostMapping
    @Override
    public Integer update(@RequestBody Report dto) {
        return this.reportService.edit(dto);
    }

    @Operation(value = "更新报销单的报销金额,和条目数量", param = "更新对象")
    @PostMapping("/update")
    public Integer updateAmountAndCount(@RequestBody ReportUpdate update){
        return this.reportService.editAmountAndCount(update);
    }

    @DeleteMapping("/{id:\\d+}")
    @Operation(value = "删除报销单", param = "id:报销单id")
    @Override
    public Integer deleteById(@PathVariable Integer id) {
        return this.reportService.removeById(id);
    }
}
